package main

import (
	"fmt"
	"sync"
	"sync/atomic"
	"time"
)

var (
	x  int64
	wg sync.WaitGroup
)

func add() {
	for i := 0; i < 500000; i++ {
		atomic.AddInt64(&x, 1)
	}

	defer wg.Done()
}

func main() {
	wg.Add(2)
	start := time.Now()

	go add()
	go add()

	wg.Wait()
	fmt.Println(time.Since(start))
	fmt.Println(x)
}
